<template>
	<view class="messageBox">
		<image src="../../static/images/success.png" mode="" style="width: 200rpx;height: 200rpx;margin-top: 160rpx;"></image>
		<view class="" style="margin-top: 60rpx;">
			签署成功, 点击查看<text @click="watch" style="color: #49806F;">《网签合同》</text>协议
		</view>
		<view  v-if="type==1" class="ft14" style="color: #999;">
				请在"我的"-"成为网红"上传与平台签约的合同
		</view>
		<view class="save_btn" @click="tosign">
			下一步
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
				type: "",
				signStatus: false,
				name: '',
				sfz: "",
				mobie: "",
				zhusuo: "",
				pdfLink: "",
				qianming: ""
			};
		},
		onLoad(opt) {
			this.signStatus = false
			this.name = opt.name
			this.sfz = opt.sfz
			this.mobie = opt.mobie
			this.zhusuo = opt.zhusuo
			this.qianming = opt.qianming
			this.type = opt.type
			this.title=opt.title


		},
		// onBackPress() {
		// 	if(this.signStatus){
		// 		uni.switchTab({
		// 			url:'/pages/tabbar/mine'
		// 		})
		// 	}

		// 	return true
		// },
		mounted() {
			let vm = this


			if (vm.type == 1) {
				vm.$api.qianming({
					qianming: vm.qianming,
					name: vm.name,
					sfz: vm.sfz,
					mobie: vm.mobie,
					zhusuo: vm.zhusuo
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						vm.pdfLink = res.data.pdf
						uni.hideLoading()

					}
				})
			} else if (vm.type == 2) {
				vm.$api.gonghuoshangqianming({
					qianming: vm.qianming,
					name: vm.name,
					sfz: vm.sfz,
					zhusuo: vm.zhusuo,
					title:vm.title
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						vm.pdfLink = res.data.pdf

					}
				})
			} else {
				vm.$api.demoWanghong({
					qianming: vm.qianming,
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						uni.$emit('success',res.data.pdf)
						vm.pdfLink = res.data.pdf
					}
				})
			}

		

	},
	onUnload() {
			uni.$off('success')
		},
		methods: {

			async getList(type) {
				const {
					data
				} = await this.$api.cardinfo({
					id: 9
				})
				console.log(data)
				this.content = data.content
				uni.setNavigationBarTitle({
					title: data.title
				})

			},
			watch() {
				let vm = this
				uni.downloadFile({
					url: vm.pdfLink,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								uni.hideLoading()
								console.log('Document opened successfully');
							},
							fail: function(err) {
								console.log('Failed to open document', err);
							}
						});
					},
					fail: function(res) {
						console.log('Download failed', res);
					}
				});
			},
			
			tosign() {
					
				if(this.type==1||this.type==2){
					uni.switchTab({
						url:'/pages/tabbar/mine'
					})
				}else{
					
					uni.navigateBack()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.messageBox {
		min-height: 100vh;
		background-color: #fff;
		padding: 24rpx;
		text-align: center;


	}

	.save_btn {
		width: 690rpx;;
		height: 90rpx;
		
		
		background: #49806F;
		border-radius: 12rpx;
		font-size: 32rpx;
		color: #FFFFFF;
		text-align: center;
		position: fixed;
		bottom: 100rpx;
		left: 0;
		right: 0;
		margin: auto;
		line-height: 90rpx;
	}
</style>